using System;
using System.Collections.Generic;

namespace Domain.Entities
{
    public class Message
    {
        private int id;
        private string text;
        private DateTime postDateTime;
        private bool moderatorsOnly;

        private Topic topic;
        private User poster;

        private IList<Attachment> attachments;

        public virtual int Id
        {
            get { return id; }
            internal set { id = value; }
        }

        public virtual string Text
        {
            get { return text; }
            internal set { text = value; }
        }
        
        public virtual DateTime PostDateTime
        {
            get { return postDateTime; }
            internal set { postDateTime = value; }
        }

        public virtual bool ModeratorsOnly
        {
            get { return moderatorsOnly; }
            internal set { moderatorsOnly = value; }
        }

        public virtual Topic Topic
        {
            get { return topic; }
            internal set { topic = value; }
        }

        public virtual User Poster
        {
            get { return poster; }
            internal set { poster = value; }
        }

        public virtual IList<Attachment> Attachments
        {
            get { return attachments; }
            internal set { attachments = value; }
        }

        public virtual Attachment GetAttachment(int localId)
        {
            foreach (Attachment attachment in attachments)
            {
                if (attachment.LocalId == localId)
                {
                    return attachment;
                }
            }
            return null;
        }
    }
}
